package cn.life.business.inspect.controller;

import cn.life.business.inspect.entity.po.Inspect;
import cn.life.business.inspect.entity.vo.InspectVo;
import cn.life.business.inspect.service.InspectService;
import cn.life.common.entity.model.CMessage;
import cn.life.common.entity.model.MyUser;
import cn.life.common.entity.model.MyUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author 王振宇
 * @Description:
 * @Date 2018-07-26 10:38:37
 */

@RestController
@RequestMapping("inspect")
public class InspectController {

    @Autowired
    private InspectService inspectService;

    /**
     * @Description:  自动添加项
     * @param   inspect,myUserInfo
     * @return
     */
    public Inspect getOpr(Inspect inspect, MyUserInfo myUserInfo){
        inspect.setOprUserId(myUserInfo.getUserId());
        inspect.setOprUserName(myUserInfo.getUserName());
        inspect.setOprDate(new Date());
        return inspect;
    }

    /**
     * @Description: 添加检测记录
     * @param inspect
     * @return
     */
    @PostMapping(value = "/addinspect")
    public  CMessage  addInspect(@RequestBody Inspect inspect,@MyUser MyUserInfo myUserInfo){
        getOpr(inspect,myUserInfo);
        return inspectService.addInspect(inspect);
    }

    /**
     * @Description: 删除检测记录
     * @param inspect
     * @return
     */
     @PostMapping(value = "/deleteinspect")
     public  CMessage deleteInspect(@RequestBody Inspect inspect){
         return inspectService.deleteInspect(inspect);
     }

    /**
     * @Description: 修改检测记录
     * @param inspect
     * @return
     */
    @PostMapping(value = "/updateinspect")
    public  CMessage updateInspect(@RequestBody Inspect inspect){
        return inspectService.updateInspect(inspect);
    }

    /**
     * @Description: 查询检测记录
     * @param inspectVo
     * @return
     */
    @PostMapping(value = "/selectinspect")
    public CMessage selectInspect(@RequestBody InspectVo inspectVo,@MyUser MyUserInfo myUserInfo){
        if(inspectVo.getProjectId() == null){
            inspectVo.setProjectId(myUserInfo.getProjectId());
        }
        inspectVo.setOprUserId(myUserInfo.getUserId());
        return inspectService.selectInspect(inspectVo);
    }


    /**
     * @Description: 查询单条（详情页）检测记录
     * @param inspectVo
     * @return
     */
    @PostMapping(value = "/getinspect")
    public  CMessage getInspect(@RequestBody InspectVo inspectVo){
        return inspectService.getInspect(inspectVo);
    }

    /**
     * @Description: 合格率统计
     * @param inspectVo
     * @return
     */
    @PostMapping(value = "/statistics")
    public CMessage statistics(@RequestBody InspectVo inspectVo){
      return inspectService.statistics(inspectVo);
    }

    /**
     * @Description: 合格率统计个人详情
     * @param inspectVo
     * @return
     */
    @PostMapping(value = "/statisticsDetails")
    public CMessage statisticsDetails(@RequestBody InspectVo inspectVo){
        return inspectService.statisticsDetails(inspectVo);
    }

}
